﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic.ClassFactory;

using Common;

namespace RichECMS.ServerPages.Links
{
    public partial class LinkGroupCurrentLeft : Util.BasePage.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LinkGroupTree.ExpandDepth = 2;
                TreeBing();
            }
        }


        private void TreeBing()
        {
            //加载站点树说明
            TreeNode objNode = new TreeNode();
            objNode.Value = "0";
            objNode.Text = "链接组一览";
            objNode.Target = "I3";
            //objNode.NavigateUrl = "SystemManage/SystemInfo.aspx";
            objNode.ImageUrl = "../../sysCommon/sysImages/sectionroot.png";
            LinkGroupTree.Nodes.Add(objNode);

            TreeNode objWebSiteNode = null;
            using (WebSiteFactory objFactory = new WebSiteFactory())
            {
                BusinessLogic.BusinessRules.WebSite objWebSite = objFactory.CreatorBySql(string.Format("intWSState ={0}", (int)Utility.WebSiteState.Use));
                if (objWebSite != null)
                {
                    foreach (Model.Data.WebSiteData.WebSiteRow objRow in objWebSite.Data.WebSite.Rows)
                    {
                        objWebSiteNode = new TreeNode();
                        objWebSiteNode.Text = objRow.chvName;
                        //objWebSiteNode.NavigateUrl = "WebSite/WebSiteSet.aspx?intWSID=" + objRow.intWebSiteID;
                        objWebSiteNode.Target = "I3";
                        objWebSiteNode.ImageUrl = "../../sysCommon/sysImages/globe.png";
                        objNode.ChildNodes.Add(objWebSiteNode);
                    }
                }
            }

            using (LinksGroupFactory objFactory = new LinksGroupFactory())
            {
                BusinessLogic.BusinessRules.LinksGroup objLinksGroup = objFactory.Creator();
                if (objLinksGroup != null)
                {
                    TreeNode rootNode = null;
                    foreach (Model.Data.LinksGroupData.LinksGroupRow objRow in objLinksGroup.Data.LinksGroup.Rows)
                    {
                        rootNode = new TreeNode();
                        rootNode.Text = objRow.chvGName;
                        rootNode.Value = objRow.intGroupID.ToString();
                        rootNode.Target = "I3";

                        rootNode.NavigateUrl = "LinksList.aspx?Gid=" + objRow.intGroupID;
                        rootNode.ImageUrl = "../../sysCommon/sysImages/treenode.png";

                        //AddTreeNode(rootNode, objRow.intGroupID);
                        if (objWebSiteNode != null) objWebSiteNode.ChildNodes.Add(rootNode);
                    }
                }
            }
        }
    }
}